package org.kumas.sgrpc.common.extension.ext1;

import org.kumas.sgrpc.common.URL;
import org.kumas.sgrpc.common.extension.ExtensionLoader;

/**
 *
 * @author KumasZhang
 * @version 1.0
 * @since 2021-07-09 12:10
 */
public class SimpleExt$Adaptive implements SimpleExt {

    @Override
    public String echo(URL url, String s) {
        if (url == null) throw new IllegalArgumentException("url == null");

        String extName = url.getParameter("simple.ext", "SimpleExtImpl1");
        if(extName == null) throw new IllegalStateException("Failed to get extension (org.apache.dubbo.common.extension.adaptive.HasAdaptiveExt) name from url (" + url.toString() + ") use keys([has.adaptive.ext])");
        SimpleExt extension = (SimpleExt) ExtensionLoader.getExtensionLoader(SimpleExt.class).getExtension(extName);
        return extension.echo(url, s);
    }

    @Override
    public String yell(URL url, String s) {
        if (url == null) throw new IllegalArgumentException("url == null");
        String extName = url.getParameter("key1", url.getParameter("key2", "SimpleExtImpl1"));
        if(extName == null) throw new IllegalStateException("Failed to get extension (org.kumas.sgrpc.common.extension.ext1.SimpleExt) name from url (" + url.toString() + ") use keys([key1, key2])");
        SimpleExt extension = (SimpleExt)ExtensionLoader.getExtensionLoader(SimpleExt.class).getExtension(extName);
        return extension.yell(url, s);
    }

    @Override
    public String bang(URL url, int i) {
        throw new UnsupportedOperationException("The method org.kumas.sgrpc.common.extension.ext1.SimpleExt$Adaptive.bang is not adaptive method!");
    }
}